import instance from "@/request/axios";

/**
 * 添加题目
 * @param answer
 * @param content
 * @param judgeCase
 * @param judgeConfig
 * @param tags
 * @param title
 */
export const addQuestion = ({ answer, content, judgeCase = [], judgeConfig = {}, tags = [], title }: any) => {
  return instance.post("/api/question/add", {
    answer,
    content,
    judgeCase,
    judgeConfig,
    tags,
    title
  });
};

/**
 * 查询题目列表
 * @param pageSize
 * @param current
 */
export const listQuestion = ({pageSize, current}: any) => {
  return instance.post("/api/question/list/page",
    {
      pageSize,
      current
    })
}

/**
 * 删除题目
 * @param id
 */
export const delQuestion = (id: any) => {
  return instance.post('/api/question/delete',
    {
      id
    })
}

/**
 * 更新题目查询回显
 * @param id
 */
export const getOldQuestion = (id: any) => {
  return instance.get('/api/question/get',{
    params: {
      id
    }
  })
}

/**
 * 更新题目
 * @param answer
 * @param content
 * @param judgeCase
 * @param judgeConfig
 * @param tags
 * @param title
 */
export const updateQuestion = ({ id, answer, content, judgeCase = [], judgeConfig = {}, tags = [], title }: any) => {
  return instance.post("/api/question/update", {
    id,
    answer,
    content,
    judgeCase,
    judgeConfig,
    tags,
    title
  });
}

/**
 * 用户浏览题目
 * @param id
 * @param answer
 * @param content
 * @param judgeCase
 * @param judgeConfig
 * @param tags
 * @param title
 */
export const userQuestionList = ({ id, answer, content, judgeCase = [], judgeConfig = {}, tags = [], title }: any) => {
  return instance.post('/api/question/list/page/vo',
    {
      id,
      answer,
      content,
      judgeCase,
      judgeConfig,
      tags,
      title
    })
}

/**
 * 做题
 * @param id
 */
export const getQuestionById = (id: string) => {
  return instance.get('/api/question/get/vo',{
    params: {
      id
    }
  })
}

/**
 * 提交题目
 * @param code
 * @param language
 * @param questionId
 */
export const submitQuestion = ({code, language, questionId}: any) => {
  return instance.post('/api/question/question_submit/do',{
    code,
    language,
    questionId
  })
}

/**
 * 获取题目提交列表
 * @param language
 * @param questionId
 * @param status
 * @param userId
 */
export const searchSubmitRes = ({language, questionId, status, userId}: any) => {
  return instance.post('/api/question/question_submit/list/page',{
    language,
    questionId,
    status,
    userId
  })
}

/**
 * 使用ai分析代码
 * @param code
 * @param language
 * @param questionId
 */
export const askToAi = ({code, language, questionId}: any) => {
  return instance.post('/api/question//submittoai',{
    code,
    language,
    questionId
  })
}

/**
 * 根据题目id获取评论
 * @param questionId
 */
export const getComment = (questionId: any) => {
  return instance.get('/api/question/getComment/' + questionId)
}
